package com.iemes.controller.transport;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.TransportSuperviseFormMap;
import com.iemes.mapper.transport.TransportSuperviseMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
@RequestMapping("/transportSupervise/")
@Controller
public class TransportSuperviseController extends BaseController{
	@Inject
	private TransportSuperviseMapper transportSuperviseMapper;
	//日常监控
		@RequestMapping("/examinetransportSupervise")
		public String examineTransport(Model model){
			model.addAttribute("res", findByRes());
			return Common.BACKGROUND_PATH+"/transport/supervise/transportsupervise_list";
		}
		@ResponseBody
		@RequestMapping("/transportSupervise_findbyPage")
		public PageView findByPage(String pageNow, String pageSize) throws Exception 
		{
			List<Map<String, Object>> transportSuperviseFormMaps = transportSuperviseMapper.getAllNum();
			for (Map<String, Object> map : transportSuperviseFormMaps) {
				if (Integer.valueOf(map.get("number").toString())>=87) {
					map.put("number", map.get("number"));
				}else if (Integer.valueOf(map.get("number").toString())<87){
					map.put("number", "不满");
				}
				
			}
			LuogicPaging(pageNow, pageSize, transportSuperviseFormMaps);
			return pageView;
		}
		//日常监控明细
		@RequestMapping(value="/transportSupervise_detalis")
		public String editDispatch(Model model) {
			String id = getPara("id").toString();
			//List<Map<String, Object>> motorcadeInfoFormMaps=motorcadeMapper.getAllInfo(null);
			//获取对象transportSuperviseFormMap
			if(Common.isNotEmpty(id))
			{
				TransportSuperviseFormMap transportSuperviseFormMap=baseMapper.findbyFrist("id", id, TransportSuperviseFormMap.class);
				String tranDate2=transportSuperviseFormMap.get("tranDate").toString();
				String tranDate=tranDate2.substring(0,7);
				
				List<TransportSuperviseFormMap> transportSuperviseFormMaps=transportSuperviseMapper.getAllInfo(tranDate);
				for (Map<String, Object> map : transportSuperviseFormMaps) {
					
					
					if (Integer.valueOf(map.get("category").toString())==1) {
						map.put("category", "物料编码");
					}else if (Integer.valueOf(map.get("category").toString())==2){
						map.put("category", "模具编号");
					}
					
				}
				System.out.println(tranDate);
				
				//model.addAttribute("transportSuperviseFormMap", transportSuperviseFormMap);
				model.addAttribute("transportSuperviseFormMap", transportSuperviseFormMaps);
				
			}
			return Common.BACKGROUND_PATH + "/transport/supervise/transportsupervise_details";
											 
		}
		//删除日常监控明细
		@ResponseBody
		@RequestMapping("transportSupervise_deleteEntity")
		@Transactional(readOnly=false)//需要事务操作必须加入此注解
		@SystemLog(module="删除日常监控明细",methods="pod按钮-删除pod按钮")//凡需要处理业务逻辑的.都需要记录操作日志
		public String deleteEntity() throws Exception {
			TransportSuperviseFormMap transportSuperviseFormMap=getFormMap(TransportSuperviseFormMap.class);
			String[] ids = getParaValues("ids");
			String arr=ids[0];
			String[] str=arr.split(",");
			for(int i=0;i<str.length;i++){
				transportSuperviseFormMap.set("status", 2);
				transportSuperviseFormMap.put("id", str[i]);
				transportSuperviseMapper.editEntity(transportSuperviseFormMap);
			}
			
			return "success";
		}
}
